package com.dragon.mmochat.model.serverListDao;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.transaction.annotation.Transactional;

import com.dragon.mmochat.model.MmochatChenHao;
import com.dragon.mmochat.model.enumType.MmochatChenHaoType;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.dragon.mmochat.model.serverListStatistics.MmochatMixDayLog;
import com.dragon.mmochat.model.serverListStatistics.MmochatPayRecord;
import com.dragon.mmochat.model.statistics.MmochatMixStatistics;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class DaoService {
	private Dao_subServer dao1;// 海誓山盟:mmochat1
	private Dao_subServer dao2;// 盖世英雄+王者归来:mmochat12
	private Dao_subServer dao3;// 一剑天下+无双+五湖四海:mmochat3
	private Dao_subServer dao4;// 天之痕+蓬莱仙境:mmochat16
	private Dao_subServer dao6;// 胜者为王:mmochat21
	private Dao_subServer dao7;// 叱咤风云+踏雪无痕:mmochat7
	private Dao_subServer dao8;// 2012:mmochat8
	private Dao_subServer dao9;// 仗剑行歌:mmochat19
	private Dao_subServer dao10;// 同舟共济+桃园结义:mmochat10
	private Dao_subServer dao11; // 2013:mmochat18
	private Dao_subServer dao12; // 普天同庆+王者归来:mmochat14
	private Dao_subServer dao13; // 轩辕剑:mmochat20

	private Dao_statistics dao5;// 统计数据库:mmochat_statistics

	// 实例号-->数据库dao对应关系:合区后需要修改此项!!!!!!!!!!!!!!!!!!!!
	private Dao_subServer getDaoByInstId(int instId) {
		switch (instId) {
		case 0x41e2:
			return dao1;
		case 0x41e4:
			return dao3;
		case 0x41e5:
			return dao4;
		case 0x41e8:
			return dao7;
		case 0x41e9:
			return dao8;
		case 0x41e7:
			return dao9;
		case 0x41e6:
			return dao10;
		case 0x41e3:
			return dao2;
		case 0x41ea:
			return dao6;
		case 0x41eb:
			return dao11;
		case 0x41ec:
			return dao12;
		case 0x41ed:
			return dao13;
		default:
			break;
		}
		return null;
	}

	public void setDao1(Dao_subServer dao1) {
		this.dao1 = dao1;
	}

	public void setDao2(Dao_subServer dao2) {
		this.dao2 = dao2;
	}

	public void setDao3(Dao_subServer dao3) {
		this.dao3 = dao3;
	}

	public void setDao4(Dao_subServer dao4) {
		this.dao4 = dao4;
	}

	public void setDao5(Dao_statistics dao5) {
		this.dao5 = dao5;
	}

	public void setDao6(Dao_subServer dao6) {
		this.dao6 = dao6;
	}

	public void setDao7(Dao_subServer dao7) {
		this.dao7 = dao7;
	}

	public void setDao8(Dao_subServer dao8) {
		this.dao8 = dao8;
	}

	public void setDao9(Dao_subServer dao9) {
		this.dao9 = dao9;
	}

	public void setDao10(Dao_subServer dao10) {
		this.dao10 = dao10;
	}

	public void setDao11(Dao_subServer dao11) {
		this.dao11 = dao11;
	}

	public void setDao12(Dao_subServer dao12) {
		this.dao12 = dao12;
	}

	public void setDao13(Dao_subServer dao13) {
		this.dao13 = dao13;
	}

	public List<Long> mmochat1_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao1.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat2_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao2.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat3_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao3.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat4_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao4.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat6_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao6.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat7_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao7.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat8_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao8.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat9_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao9.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat10_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao10.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat11_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao11.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat12_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao12.getSkyIdByDate(start, end);
	}

	public List<Long> mmochat13_getSkyIdByDate(Timestamp start, Timestamp end) {
		return dao13.getSkyIdByDate(start, end);
	}

	@Transactional
	public void addNewDayLog(long time, int reg_new_skyid_num,
			int login_times_average, int login_skyid_num,
			int directpay_total_money, int directpay_skyid_num,
			int directpay_times, int kb_total_money, int kb_skyid_num,
			int kb_times, int mixPaySkyIdNum) {
		dao5.addNewDayLog(time, reg_new_skyid_num, login_times_average,
				login_skyid_num, directpay_total_money, directpay_skyid_num,
				directpay_times, kb_total_money, kb_skyid_num, kb_times,
				mixPaySkyIdNum);
	}

	// 获取指定时间内的充值卡充值记录
	public List<MmochatPayRecord> mmochat1_getDirectPayRecord(long start,
			long end) {
		return dao1.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat2_getDirectPayRecord(long start,
			long end) {
		return dao2.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat3_getDirectPayRecord(long start,
			long end) {
		return dao3.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat4_getDirectPayRecord(long start,
			long end) {
		return dao4.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat5_getDirectPayRecord(long start,
			long end) {
		return dao5.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat6_getDirectPayRecord(long start,
			long end) {
		return dao6.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat7_getDirectPayRecord(long start,
			long end) {
		return dao7.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat8_getDirectPayRecord(long start,
			long end) {
		return dao8.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat9_getDirectPayRecord(long start,
			long end) {
		return dao9.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat10_getDirectPayRecord(long start,
			long end) {
		return dao10.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat11_getDirectPayRecord(long start,
			long end) {
		return dao11.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat12_getDirectPayRecord(long start,
			long end) {
		return dao12.getDirectPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat13_getDirectPayRecord(long start,
			long end) {
		return dao13.getDirectPayRecord(start, end);
	}

	// 获取指定时间内的K币充值记录
	public List<MmochatPayRecord> mmochat1_getKBPayRecord(long start, long end) {
		return dao1.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat2_getKBPayRecord(long start, long end) {
		return dao2.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat3_getKBPayRecord(long start, long end) {
		return dao3.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat4_getKBPayRecord(long start, long end) {
		return dao4.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat5_getKBPayRecord(long start, long end) {
		return dao5.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat6_getKBPayRecord(long start, long end) {
		return dao6.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat7_getKBPayRecord(long start, long end) {
		return dao7.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat8_getKBPayRecord(long start, long end) {
		return dao8.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat9_getKBPayRecord(long start, long end) {
		return dao9.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat10_getKBPayRecord(long start, long end) {
		return dao10.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat11_getKBPayRecord(long start, long end) {
		return dao11.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat12_getKBPayRecord(long start, long end) {
		return dao12.getKBPayRecord(start, end);
	}

	public List<MmochatPayRecord> mmochat13_getKBPayRecord(long start, long end) {
		return dao13.getKBPayRecord(start, end);
	}

	// 获取指定时间内的各区综合数据记录
	public List<MmochatMixDayLog> getMixDayLog(long start, long end) {
		return dao5.getMixDayLog(start, end);
	}

	// 查询指定时间内的每日记录
	public List<MmochatMixStatistics> mmochat1_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao1.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat2_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao2.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat3_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao3.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat4_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao4.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat5_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao5.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat6_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao6.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat7_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao7.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat8_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao8.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat9_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao9.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat10_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao10.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat11_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao11.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat12_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao12.getDayLogByTime(startDate, endDate);
	}

	public List<MmochatMixStatistics> mmochat13_getDayLogByTime(
			Timestamp startDate, Timestamp endDate) {
		return dao13.getDayLogByTime(startDate, endDate);
	}

	public MmochatPlayer getRole(int roleId, int serverInstId) {
		Dao_subServer curDao = getDaoByInstId(serverInstId);
		if (curDao == null) {
			return null;
		}
		return curDao.getRole(roleId);
	}

	@Transactional
	public void updatePkScore(int roleId, int serverInstId, int pkScore) {
		Dao_subServer curDao = getDaoByInstId(serverInstId);
		if (curDao == null) {
			return;
		}
		curDao.updatePkScore(pkScore, roleId);
	}

	public Map<MmochatChenHaoType, MmochatChenHao> getChenHao(int roleId,
			int serverInstId) {
		Dao_subServer curDao = getDaoByInstId(serverInstId);
		if (curDao == null) {
			return null;
		}
		String data = curDao.getChenHao(roleId);
		if (data == null) {
			return null;
		}
		Gson gson = new Gson();
		Map<MmochatChenHaoType, MmochatChenHao> map = gson.fromJson(data,
				new TypeToken<Map<MmochatChenHaoType, MmochatChenHao>>() {
				}.getType());
		if (map != null) {
			map = new ConcurrentHashMap<MmochatChenHaoType, MmochatChenHao>(map);
			return map;
		}
		return null;
	}

	@Transactional
	public void updatePkScoreAndChenHao(int roleId, int serverInstId,
			int pkScore, String chenHao) {
		Dao_subServer curDao = getDaoByInstId(serverInstId);
		if (curDao == null) {
			return;
		}
		curDao.updatePkScoreAndChenHao(pkScore, chenHao, roleId);
	}
}
